package com.lc.springboot.config.datasource.springmvc;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;

import java.util.Properties;

/**
 * springmvc 相关的配置
 * @author lengchuan <lishuijun1992@gmail.com>
 * @date 16-9-1
 */
@Configuration
public class SpringMvcConfig {

    /**
     * 异常处理
     *
     * @return
     */
    @Bean
    public SimpleMappingExceptionResolver mappingExceptionResolver() {
        SimpleMappingExceptionResolver mappingExceptionResolver = new SimpleMappingExceptionResolver();

        //shiro没有权限
        Properties properties = new Properties();
        //(异常，url)
        properties.setProperty("org.apache.shiro.authz.UnauthorizedException", "/unauthorized");

        //TODO 其它异常处理
        mappingExceptionResolver.setExceptionMappings(properties);
        return mappingExceptionResolver;
    }
}
